from django.db import models
from apps.common.base.models import BaseModel
from apps.user.models import UserModel
from apps.system.dict.models import Dict

class Article(BaseModel):
    '''文章模型'''

    status = (
        ("initial", "草稿"),
        ("checking", "审核中"),
        ("publish", "已发布"),
    )
    cate = models.ForeignKey(Dict, related_name='cate_article', verbose_name='分类', on_delete=models.SET_NULL, null=True,
                             blank=True, db_constraint=False)
    title = models.CharField("标题", max_length=200, blank=True, default='')
    subTitle = models.CharField("副标题", max_length=200, blank=True, default='')
    coverUrl = models.CharField("封面", max_length=200, blank=True, null=True, default='')
    content = models.TextField("内容", max_length=10000, null=True, blank=True, default='')
    hots = models.IntegerField("阅读人数", default=0)
    users = models.ManyToManyField(UserModel, related_name='users_article', blank=True, default=[], db_constraint=False)
    isInform = models.BooleanField("是否被举报", default=False)
    status = models.CharField("状态", max_length=200, choices=status, blank=True, default='publish')

    class Meta:
        verbose_name = 'Article'
        verbose_name_plural = verbose_name
